// 引入小仓库
import { reqC1List ,reqC2List,reqC3List} from "@/api/product/attr/attr";
import { defineStore } from "pinia";

let useCategoryStore = defineStore('category',{
    // 存储数据
    state:()=>{
        return{
            // 存储一级分类的数据
            c1List:[],
            c2List:[],
            c3List:[],
            // 存储一级分类的id
            c1Id:'',
            c2Id:'',
            c3Id:'',
        }
    },
    // 处理业务的地方,同步和异步都可以
    actions:{
        async getC1List(){
            let result = await reqC1List()
            this.c1List = result
        },
        async getC2List(){
            // 一级目录的id改变时,清空二级和三级目录
            this.c2Id = ''
            this.c3Id = ''
            this.c2List = []
            this.c3List = []
            let result =await reqC2List(this.c1Id)
            this.c2List = result
        },
        async getC3List(){
            // 二级目录的id改变时,清空三级目录
            this.c3Id = ''
            this.c3List = []
            let result = await reqC3List(this.c2Id)
            this.c3List = result
        }
    }
})

// 对外暴露小仓库
export default useCategoryStore